package com.rongshu.sendmessage.util.event;

import java.util.HashMap;

/**
 * Created by lx on 2017/6/9.
 */
public abstract class BaseEventBuilder {

    protected HashMap<String, Class<? extends IEvent>> eventCache = new HashMap<>();

    public HashMap<String, Class<? extends IEvent>> buildEvents(){
        registEvents();
        return eventCache;
    }

    /**
     * 注册系统事件避免事件发送乱
     */
    public abstract void registEvents();

    /**
     * 对应关系
     * @param eventCls 事件类
     * @param subscribeCls 订阅者类
     * @param subscribeClsMethodName 订阅者类对应的方法
     */
    public void create(Class<? extends IEvent> eventCls, Class<?> subscribeCls, String subscribeClsMethodName) {
        eventCache.put(subscribeCls.getSimpleName()+"_" +subscribeClsMethodName,eventCls);
    }

    public void removeEvent(Class<?> subscribeCls, String subscribeClsMethodName) {
        String key = subscribeCls.getSimpleName()+"_" +subscribeClsMethodName;
        eventCache.remove(key);
    }
    public void clear(){
        eventCache.clear();
    }
}
